/*
brief:游戏作弊码

*/



#include "game_util/game_cheat.h"
#include "str_util.h"
#include "misc.h"


using namespace std;
using namespace su;

std::string GameCheat::DoCmd(GamePlayer& player, const char *pChar )
{

	VecStr vec_str;
	VecStr vec_split;
	vec_split.push_back(";");
	vec_split.push_back(",");
	vec_split.push_back(".");
	vec_split.push_back(" ");
	vec_split.push_back(":");
	StrUtil::split(pChar, vec_split, vec_str );
	if (vec_str.empty())
	{
		return "no string";
	}
	auto it = GameCheat::Ins().m_str2DoPlayerCmdFun.find(StrUtil::tolower(vec_str.front()));
	if (it== GameCheat::Ins().m_str2DoPlayerCmdFun.end())
	{
		string ret= "can't find handle function: ";
		ret += vec_str.front();
		return ret;
	}
	vec_str.erase(vec_str.begin());
	DoPlayerCmdFun p_fun = it->second;
	return p_fun(player, pChar);

}

std::string GameCheat::DoCmd(const char *pChar)
{
	VecStr vec_str;
	VecStr vec_split;
	vec_split.push_back(";");
	vec_split.push_back(",");
	vec_split.push_back(".");
	vec_split.push_back(" ");
	vec_split.push_back(":");
	StrUtil::split(pChar, vec_split, vec_str);
	if (vec_str.empty())
	{
		return "no string";
	}

	auto it = GameCheat::Ins().m_str2DoCmdFun.find(StrUtil::tolower(vec_str.front()));
	if (it == GameCheat::Ins().m_str2DoCmdFun.end())
	{
		string ret = "can't find handle function: ";
		ret += vec_str.front();
		return ret;
	}
	vec_str.erase(vec_str.begin());
	DoCmdFun p_fun = it->second;
	return p_fun(pChar);
}

std::string su::GameCheat::DoCmd(GamePlayer& player, const std::string& str)
{
	return DoCmd(player, str.c_str());
}

std::string su::GameCheat::DoCmd(const std::string& str)
{
	return DoCmd(str.c_str());
}

